package com.powernode.controller;

import com.github.pagehelper.PageInfo;
import com.powernode.WebUtils.WebMvcUtils;
import com.powernode.commons.Result;
import com.powernode.domain.VisitLog;
import com.powernode.dto.VisitLogDto;
import com.powernode.service.VisitLogService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("visitLog")
public class VisitLogController {

    @Resource
    public VisitLogService visitLogService;


    /**
     * 添加拜访数据
     * @param visitLog
     * @return
     */
    @RequestMapping("addVisitLog.do")
    public Result addVisitLog(VisitLog visitLog){
        try{
           //设置用户的id跟用户姓名
            visitLog.setUserId(WebMvcUtils.getCurrentUser().getId());
            visitLog.setRealname(WebMvcUtils.getCurrentUserName());
            //保存
            this.visitLogService.insertSelective(visitLog);
            return Result.ADD_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return Result.ADD_ERROR;
        }
    }

    /**
     * 根据客户id查询当前客户的拜访记录
     */
    @RequestMapping("listVisitLogByCustomerId.do")
    public Result listVisitLogByCustomerId(VisitLogDto visitLogDto){
        PageInfo<VisitLog> pageInfo=this.visitLogService.listVisitLogByCustomerId(visitLogDto);
        return new Result(0,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

}
